from airtest.core.api import *
from launch import App


def close_all_windows(element):
    """
    关闭所有弹窗
    :param element: 弹窗X关闭按钮
    :return: 退出
    """
    while 1:
        print("弹窗关闭元素对象：", element)
        if element.exists():
            print("弹窗元素对象存在与否：", element.exists())
            element.click()
            sleep(1)
        else:
            print("没有弹窗：", element.exists())
            break


def swipe_element(element):
    """
    每日任务滑动
    :return:
    """
    poco = App.start()
    for i in range(10):
        try:
            element.click()
            print("-------点击对应任务后的按钮-------")
            break
        except Exception:
            poco.swipe([0.193336487, 0.7866745], [0.193336487, 0.44934082], duration=2)
            print("--------滑动---------")
            sleep(1)


def apperance_element_click(element):
    """
    元素出现就点击，不出现就略过
    :param element:
    :return:
    """
    poco = App.start()
    while 1:
        if not element.exists():
            poco.click([0.5, 0.5])
        else:
            break
